<%@ page language="java"  pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>生成子账号(注册码)</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script type="text/javascript" src="js/ext-all.js"></script>
  	<script type="text/javascript">	
  	// For IE, trim is unsupported.
	if(typeof String.prototype.trim !== 'function') {
	  String.prototype.trim = function() {
	    return this.replace(/^\s+|\s+$/g, ''); 
	  }
	}
 	function newUser()
 	{
 		var point = document.getElementById('point').value.trim() ;
 		var valid_code = document.getElementById('validCodeAnswer').value.trim();
 		if (point == '' || valid_code == '')
 		{
 			alert('所有输入项不能为空');
 			return;
 		}
		Ext.Ajax.request({
			url: 'user',
			method: 'GET',
			params: {
		        'actionType' : 'createAccount',
		        'point' : point,
		        'validCodeAnswer': valid_code,
		    },
			success: function(transport) {
				var result = transport.responseText;
				if (result.length >= 32)
				{
					alert('新的子账号(注册码)为：'+result);
					window.location.href='user/actionType=listAccount';
				}
				else
				{
					alert(result);
					show(document.getElementById('validImg'));
				}
	  		}
		});
	}
	function show(o) {
	  // 重新载入验证码
	  var timenow = new Date().getTime();
	  o.src = "validatecode?d=" + timenow;
	 }
  	</script>
  </head>
  <body>
	<table>
		<tr>
			<td width=100 title="数字、字母、下划线组成的6-20位的字符串">点数</td>
			<td><input type="text" name="point" id="point" value='' maxlength=10/></td>
		</tr>
		<tr>
			<td width=120>验证码:</td>
			<td><img src="validatecode" name="validImg" id="validImg"/><input type="text" name="validCodeAnser" id="validCodeAnswer" value='' maxlength=4/><a href="javascript:show(document.getElementById('validImg'))">看不清?</a></td>
		</tr>
		<tr>
    		<td><input type="submit" name="submit" id="submit" value="生成子账号" onClick="newUser()" /></td>
		</tr>
	</table>
  </body>
</html>
